# import packages
import psycopg2
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.dialects.postgresql.base import PGDialect
PGDialect._get_server_version_info=lambda  *args: (9,2)
# establish connections
conn_string = "postgresql+psycopg2://root:hyb12345678!@1.94.255.17:8000/gaussdemo"
db = create_engine(conn_string)
conn = db.connect()
conn1 = psycopg2.connect(
database="gaussdemo",
user='root',
password='hyb12345678!',
host='1.94.255.17',
port= '8000'
)
conn1.autocommit = True
cursor = conn1.cursor()
# drop table if it already exists
cursor.execute('drop table if exists parquetab')
sql = '''CREATE TABLE parquetab(Name varchar ,
Age int ,City varchar);'''
cursor.execute(sql)
# import the csv file to create a dataframe
data = pd.read_parquet("example.parquet")
data = data[["Name","Age","City"]]
# Create DataFrame
#print(data)
# converting data to sql
data.to_sql('parquet', conn, if_exists= 'replace')
print('parquet数据成功导入gauss')
# fetching all rows
sql1 = '''select * from parquetab;'''
cursor.execute(sql1)
for i in cursor.fetchall():
    print(i)

conn1.commit()
conn1.close()
